package com.qwz.example;

import lombok.Getter;
/**
* @Description: 封装授权数据中重复出现部分的享元对象
* @Package com.qwz.example.AuthorizationFlyWeight
* @author Qiuwuzhi
* @date 2019/12/23 15:53
* @version V1.0
*/
@Getter
public class AuthorizationFlyWeight implements FlyWeight{
    /**
     * 内部状态，安全实体
     */
    private String securityEntity;
    /**
     * 内部状态，权限
     */
    private String permit;

    /**
     * 传入状态数据
     * @param state
     */
    public AuthorizationFlyWeight(String state) {
        String[] s = state.split(",");
        this.securityEntity = s[0];
        this.permit = s[1];
    }

    public boolean match(String securityEntity, String permit) {
        if (this.securityEntity.equals(securityEntity) && this.permit.equals(permit)) {
            return true;
        }
        return false;
    }

    @Override
    public String toString() {
        return "AuthorizationFlyWeight="+this.hashCode() +" {" + "securityEntity='" + securityEntity + '\'' +
                ", permit='" + permit + '\'' + '}';
    }
}
